{% extends "hall.html" %}
{% block details %}
<ul>
    <p style="text-align: center;">创建房间</p>
    <br>
    <li>房间ID</li><input type="text" class="form-control" style="color: black;text-align: center; width: 95%;" id="id" maxlength="6" onkeyup="value=value.replace(/[^\d]/g,'')" placeholder="只能输入数字,不能以0开始.">
</ul>
<button type="button" class="btn" style="margin-right: 11.4%;" onclick="rand()">随机生成</button>
<button type="button" class="btn" style="margin-left: 12%;" id="send">确定</button>
<script>
    function ShowResult(data){
        console.log(data['status']);
        console.log(data['error']);
        if(data['status']==-1){
            alert(data['error']);
        }else{
            window.location.href='/gobang/battle/'+id.value+'/';
            // alert('/hall/create/'+id.value+'/');
        }
    }
    id=document.getElementById('id');
    function rand(){
        var data=String(Date.now());
        data=data.slice(-6,data.length);
        if(data[1]==0){
            data[1]=1;
        }
        id.value=data;
    }

    $("#send").click(function(){
        if(id.value[0]==0){
            alert('不能以0开始！');
            return;
        }
        $.ajax({
                url:'/hall/create/',
                type:'POST',
                data:{'roomID':id.value},
                success:ShowResult
            })
    })

</script>
<style>
ul li{
    text-align: left;
}
li textarea{
    text-align: center;
}
</style>
{% endblock %}